package com.dinree.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.base.library.TopBarBaseActivity;
import com.base.library.utils.StringUtils;
import com.dinree.R;
import com.dinree.api.UserApi;
import com.dinree.bean.UserBean;
import com.dinree.databinding.ActivityEditRefereeBinding;
import com.jakewharton.rxbinding2.view.RxView;

import java.util.concurrent.TimeUnit;

import static com.base.library.Constant.WINDOW_DURATION;

public class EditRefereeActivity extends TopBarBaseActivity {
    private ActivityEditRefereeBinding activityEditRefereeBinding;
    private UserBean userBean;

    @Override
    public int getContentView() {
        return R.layout.activity_edit_referee;
    }

    @Override
    public void initContentView(Bundle savedInstanceState) {
        activityEditRefereeBinding = getContentViewBinding();
        userBean = realm.findFirst(UserBean.class);
        setTitle("填写推荐人");
        setTopLeftButton(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        RxView.clicks(activityEditRefereeBinding.btnSubmit).throttleFirst(WINDOW_DURATION, TimeUnit.SECONDS).subscribe(v -> {
            submit();
        });
    }

    private void submit() {
        String name = activityEditRefereeBinding.name.getText().trim();
        String phone = activityEditRefereeBinding.phone.getText().trim();
        String com_name = activityEditRefereeBinding.comName.getText().trim();
        String com_address = activityEditRefereeBinding.comAddress.getText().trim();
        if (StringUtils.isEmpty(name)) {
            showMsg("业务员姓名不能为空");
            return;
        }
        if (StringUtils.isEmpty(phone)) {
            showMsg("业务员手机号不能为空");
            return;
        }
        if (StringUtils.isEmpty(com_name)) {
            showMsg("业务员企业名字不能为空");
            return;
        }
        if (StringUtils.isEmpty(com_address)) {
            showMsg("业务员企业地址不能为空");
            return;
        }                    if(userBean!=null){

            UserApi.getInstance(mContext).saveBasicInfo(userBean.user_id, userBean.user_token, "", "", "", "", "", "", "", "", "", "", "", name, phone, com_name, com_address).subscribe(s -> {
            Intent intent = new Intent(mContext, MainActivity.class);
            startActivity(intent);
        }, e -> {
        });}
    }
}

